﻿using System;
using System.Collections.Generic;
using System.Text;
using StarBotDotNet;

namespace StarBotDotNet
{
    public class UnitData:IComparable<UnitData>
    {
        public UnitData(Unit unit, int tick)
        {
            this.unit = unit;
            this.lastAttacked = -1;
            this.lastVisible = -1;
        }

        Unit unit;

        public Unit Unit
        {
            get { return unit; }
        }

        public bool IsDead
        {
            get
            {
                return unit.HitPoints <= 0;
            }
        }

        public int ID
        {
            get
            {
                return unit.ID;
            }
        }

        public bool IsIdle
        {
            get
            {
                return unit.Order == Constants.Order.PlayerGuard || unit.Order == Constants.Order.Nothing2;
            }
        }

        public override string ToString()
        {
            return unit.ToString();
        }

        public bool OwnedByPlayer
        {
            get
            {
                return unit.PlayerID == CurrentPlayer.PlayerID;
            }
        }

        public bool IsWorker
        {
            get
            {
                return unit.Type.Worker;
            }
        }


        public void UpdateUnit(Unit newUnit, int tick)
        {
            if ((newUnit.Shields < unit.Shields)||(newUnit.HitPoints<unit.HitPoints))
            {
                lastAttacked = tick;
            }

            lastVisible = tick;
            this.unit = newUnit;
            
        }

        public UnitType Type
        {
            get
            {
                return unit.Type;
            }
        }

        int lastAttacked;

        int lastVisible;

        #region IComparable<UnitData> Members

        public int CompareTo(UnitData other)
        {
            return unit.ID.CompareTo(other.unit.ID);
        }

        #endregion
    }
}
